package com.pj.project.update_package;

import com.pj.project.update_log.UpdateLog;
import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.text.NumberFormat;
import java.util.Date;

@Data
public class PackageInfo {

    public String topic;

    public String fileName;

    public Integer logId;

    public byte blockNumber;

    public byte[] fileBytes;

    public int dynamicSize;

    public int maxSize;

    public int cNum;

    public int packageSize = 256;

    public UpdateLog logInfo;

    public void setDynamicSize(int dynamicSize) {
        if(null == logInfo){
            logInfo = new UpdateLog();
        }
        this.dynamicSize = dynamicSize;
        this.logInfo.setDynamicSize(dynamicSize);
        String format = NumberFormat.getNumberInstance().format(dynamicSize /(float)maxSize * 100);
        if(format.compareTo("100") < 0){
            format = "100";
        }
        this.logInfo.setNum(format);
    }


    public void setPackageInfo(String topic,String fileName,byte blockNumber,byte[] fileBytes,int dynamicSize){
        this.topic = topic;
        this.fileName = fileName;
        this.blockNumber = blockNumber;
        this.fileBytes = fileBytes;
        this.maxSize = fileBytes.length;
        this.dynamicSize = dynamicSize;
    }
}
